$(function () {
    // 清除所有缓存查询条件
    sessionStorage.removeItem('userKeyWord');
    sessionStorage.removeItem('deviceKeyWord');
})

function loadUserInfo() {
    let wechatUserId = $('#hiddenUserId').val()

    if (null === wechatUserId || wechatUserId === '') {
        wechatUserId = sessionStorage.getItem('loginWeChatUserId');
    } else {
        sessionStorage.setItem('loginWeChatUserId', wechatUserId);
    }

    showLoading();

    $.post(serverUrl + ':' + serverPort + serverName + '/user/info', {
        id: wechatUserId
    }, function (result) {
        hideLoading();

        let obj = JSON.parse(result);

        sessionStorage.setItem("loginUserId", obj.data.id);
        sessionStorage.setItem("loginUserAvatar", obj.data.avatar);
        sessionStorage.setItem("loginUserName", obj.data.name);
        sessionStorage.setItem("loginUserNickName", obj.data.nickName);
        sessionStorage.setItem("loginUserSex", obj.data.sex);
        sessionStorage.setItem("loginUserMobile", obj.data.mobile);
        sessionStorage.setItem("loginUserDescription", obj.data.description);

        $('#userAvatar').prop('src', obj.data.avatar);
        $('#userName').text(obj.data.name);
        $('#userNickName').text('微信昵称：' + obj.data.nickName);

        if (obj.data.companyList.length > 0) {
            $('#userManage').css('display', '');
            $('#deviceManage').css('display', '');
            $('#invitationManage').css('display', '');

            let userCompanyIdList = '';

            $.each(obj.data.companyList, function (i, item) {
                userCompanyIdList += item.name + '-' + item.id + '@';
            });

            sessionStorage.setItem("userCompanyIdList", userCompanyIdList);
        } else {
            sessionStorage.setItem("userCompanyIdList", '');
        }
    });
}